<template>
    <div>

        <!--        顶部滑动条区域-->
        <div id="slider" class="mui-slider ">
            <div id="sliderSegmentedControl"
                 class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id == 0 ? 'mui-active' : ' ']"
                       v-for="item in cates" :key="item.id"
                       @click="getPhotoListBycatesId(item.id)"
                    >
                        {{item.title}}
                    </a>


                </div>
            </div>

        </div>
        <!--        图片列表区域-->
        <ul class="photo-list">
            <router-link tag="li" v-for="item in list" :key="item.id" :to="'/home/photoinfo/'+item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    // 导入mui
    import mui from '../../lib/js/mui.min.js'

    export default {
        data() {
            return {
                cates: [],
                list: []
            }
        },
        // 页面刚初始化，来获取数据
        created() {
            this.getAllCategory();
            // 默认进入页面请求全部图片
            this.getPhotoListBycatesId(0);

        },
        //当组件中的Dom结构被渲染好，并且放到页面中去，会执行这个钩子函数
        mounted() {
            // 初始化
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0006 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods: {
            getAllCategory() {
//获取所有的图片类
                this.$http.get('api/getimgcategory').then(result => {
                    console.log(result.body.message)
                    if (result.body.status === 0) {
                        console.log("123")
                        result.body.message.unshift({title: '全部分类', id: 0})
                        this.cates = result.body.message
                    }
                })
            },
            getPhotoListBycatesId(catesId) {
                // 根据 分类 id 获取图片的列表
                this.$http.get('api/getimages/' + catesId).then(result => {
                    console.log(result.body.message);
                    if (result.body.status === 0) {
                        console.log("123")
                        this.list = result.body.message;
                    }
                })
            }
        }
    }
</script>

<style lang="less" scoped>
    /*chrome：为提高用户体验的流畅度，用于指定某个区域容许用户操作，以及如何响应*/
    * {
        touch-action: pan-y;
    }

    .mui-segmented-control.mui-scroll-wrapper .mui-control-item {
        padding: 0 17px;
    }

    .photo-list {
        list-style: none;
        margin: 0px;
        padding: 10px;
        padding-bottom: 0;

        li {
            background-color: #ccc;
            text-align: center;
            width: 100%;
            height: 100%;
            margin-bottom: 10px;
            box-shadow: 0 0 9px #999;
            position: relative;

            img {
                width: 100%;
                vertical-align: middle;
            }

            img[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }

            .info {
                color: white;
                text-align: left;
                background-color: rgba(0,0,0,.4);
                position: absolute;
                bottom: 0;
                max-height: 84px;

                .info-title {
                    font-size: 14px;
                }

                .info-body {
                    font-size: 13px;
                }
            }
        }
    }


</style>